home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 February / LiquidLibrary 2005 February - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_dscp.ps < prev    next >
Text File  |  2003-01-03  |  4KB  |  109 lines

  1. %  Copyright (C) 2000 Artifex Software Inc.   All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. %  Postscript interface routines to DSC parser
  7.  
  8. /send_orientation {            % <orientation> send_orientation -
  9.     % .parse_dsc_comments returns -1 for an Orientation key with an
  10.     % unrecognized value.
  11.   dup 0 ge {
  12.     << /Orientation 2 index >> setpagedevice
  13.   } if pop
  14. } bind def
  15.  
  16. % This dictionary contains local handlers for DSC comments.
  17. % See header in zdscpars.c for more information.
  18. % <dsc_dict> handler <dsc_dict>
  19. /DSCparseprocs mark
  20.    /Orientation { dup /Orientation get send_orientation } bind
  21.    /PageOrientation { dup /PageOrientation .knownget { send_orientation }
  22.               { dup /Orientation .knownget { send_orientation } if }
  23.               ifelse } bind
  24.    /Page { dup /Orientation .knownget { send_orientation } if } bind
  25.    /NOP { } bind
  26. .dicttomark readonly def
  27.  
  28. % This procedure is called whenever a DSC comment is found by the interpreter
  29. /do_parse_dsc false def
  30. /parse_dsc {                % <file> <DSC string> [<prev proc>]
  31.                     %   parse_dsc -
  32.     % Run any previously installed parser.
  33.   0 get dup null eq { pop } { 3 copy exec pop } ifelse
  34.  
  35.   do_parse_dsc {            % Check if this parser is enabled
  36.     currentglobal true setglobal    % Go to global VM, save old state
  37.     3 1 roll                % Put old VM state under <file> <string>
  38.     dsc_dict exch            % <VM state> <file> <dict> <string>
  39.     .parse_dsc_comments            % <VM state> <file> <dict> <DSC name>
  40.     4 -1 roll                % Get old VM state from under <file> <dict> <DSC name>
  41.     setglobal                % restore previous VM state
  42.     //DSCparseprocs exch .knownget {    % Check DSC name against local handler list
  43.       exec                % execute any local handler
  44.     } if
  45.   } if
  46.   pop pop                % remove file, dict
  47. } bind def
  48.  
  49.  
  50. % Check whether the currently installed parser is the one defined in this file.
  51. /.using_parse_dsc {            % - .using_parse_dsc <proc> <using?>
  52.   currentuserparams /ProcessDSCComment get
  53.   dup null eq { pop {{//null} //parse_dsc exec} } if
  54.   dup length 3 eq {
  55.     dup dup length 1 sub get /parse_dsc load eq
  56.   } {
  57.     false
  58.   } ifelse
  59. } bind def
  60.  
  61. % Establish a binding for dsc_dict.
  62. userdict /dsc_dict null put
  63.  
  64. % - dsc_init -
  65. /dsc_init {                % Initialize DSC parser
  66.   currentglobal true setglobal
  67.   /dsc_dict 50 dict store        % Size must be large enough for all DSC values
  68.   dsc_dict .initialize_dsc_parser
  69.   .using_parse_dsc {
  70.     % Already using this parser.
  71.     pop
  72.   } {
  73.     % Encapsulate the previous parser.  We know it is in global VM:
  74.     % allocate the new one in global VM as well.
  75.     1 array astore
  76.     /parse_dsc load /exec load 3 array astore cvx readonly
  77.     << /ProcessDSCComment 3 -1 roll >>
  78.     setuserparams
  79.   } ifelse
  80.   setglobal
  81.   /do_parse_dsc true def
  82. } bind def
  83.  
  84.  
  85. % Enable the DSC parser defined in this file.
  86. % - enable_dsc -
  87. /enable_dsc {
  88.   dsc_init
  89. } bind def
  90.  
  91. % Disable the DSC parser defined in this file.
  92. % - disable_dsc -
  93. /disable_dsc {
  94.     % There might be another parser installed: if so, restore it.
  95.     % (If it has encapsulated our parser, we can't.)
  96.   .using_parse_dsc {
  97.     % Restore the parser we encapsulated.
  98.     0 get 0 get
  99.     currentglobal true setglobal exch
  100.     << /ProcessDSCComment 3 -1 roll >>
  101.     exch setglobal setuserparams
  102.   } {
  103.     pop
  104.   } ifelse
  105.     % If we couldn't restore the old parser, at least disable ours.
  106.   /do_parse_dsc false def
  107. } bind def
  108.